/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helper;


import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.list.ListCellRenderer;
import java.io.IOException;


import model.ItemMenu;
/**
 *
 * @author Hallucinogen5
 */

public class ListRenderer extends Container implements ListCellRenderer{
    //Variable
    private Label content = new Label("");
    private Label focus = new Label("");
    private Image focusImg;
    public static float gapBetween = 12.5f;

    //Default constructor
    public ListRenderer(){
        System.out.println("ListRenderer()");
        Image img = null;
        try {
            img = Image.createImage("/res/image/selection.png");
        } catch (IOException ex) {
            System.out.println("Background image not found");
        }
        
        this.setLayout(new BorderLayout());
        this.addComponent(BorderLayout.WEST, content);

        focus.getStyle().setBgImage(img);
        
    }

    //User-defined constructor
    public ListRenderer(String mode){
        setLayout(new BorderLayout());
        addComponent(BorderLayout.WEST, content);

        focus.getStyle().setBgColor(0xFFFF00);
        focus.getStyle().setFgColor(0xFFFFFF);
    }

    //User-defined constructor
    public ListRenderer(Image focusImg){
        setLayout(new BorderLayout());
        addComponent(BorderLayout.CENTER, content);

        focus.getStyle().setBgTransparency(0);
        focus.setIcon(focusImg);

        this.focusImg = focusImg;
    }

    public Component getListCellRendererComponent(List list, Object o, int i, boolean isSelected) {
        if(o instanceof Image){
            content.setIcon((Image) o);
            
            content.setAlignment(Component.LEFT);
            if(this.focusImg != null)
                content.getStyle().setMargin(0, 0, focusImg.getWidth(), 0);
                content.getStyle().setBgTransparency(0);
        } else if (o instanceof String){ //String
            content.setText(o.toString());
            
            content.getStyle().setBgTransparency(0);
            content.getStyle().setFgColor(0x000000);
        } else if (o instanceof ItemMenu) { //Item data
            //Set the image
//            content.setIcon(((ItemMenu)o).Icon);
            //Set item name as text

            ItemMenu menu = (ItemMenu) o;
            content.setText(((ItemMenu)o).getMenuName());
//            System.out.println("name item menu"+menu.getMenuName());
            //content.sets`
            Font font = Font.createSystemFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_MEDIUM);
            content.getStyle().setFont(font);
            //No background
            content.getStyle().setBgTransparency(0);
            content.getStyle().setFgColor(0x000000);


        }     
        return this;
    }

    public Component getListFocusComponent(List list) {
        return focus;
    }
}